package com.chaopei.cxjw.controller;

import com.alibaba.fastjson.JSON;
import com.chaopei.cxjw.entity.Student;
import com.chaopei.cxjw.service.StudentService;
import com.chaopei.cxjw.service.impl.StudentServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@CrossOrigin
@RestController
public class StudentController {
    @Resource
    StudentService studentService = new StudentServiceImpl();
    @RequestMapping(value = "/student",produces = "text/html;charset=UTF-8")
    public String student(){
        List<Student> list = new ArrayList<>();
        Student[] students = studentService.selectAllStudent();
        for (int i = 0; i < students.length; i++) {
            list.add(students[i]);
        }
        String json = JSON.toJSONString(list);
        System.out.println(json);
        return json;
    }
}
